// CGALSegments.cpp : definisce il punto di ingresso dell'applicazione console.
// Uso dei circulator

#include "stdafx.h"

#define FRACT 10.0
#define MIN_DIST 0.001

int _tmain(int argc, _TCHAR* argv[])
{
	Segment s1(Point(1,2), Point(1,10)),
			s2(Point(1,10), Point(11,10)),
			s3(Point(3,6), Point(1,2));
	cout << "CGAL angle" << endl;
	cout << "Segmento s1 " << s1 << endl;
	cout << "Segmento s2 " << s2 << endl;
	cout << "Segmento s3 " << s3 << endl;
	cout << "Angolo s1 " << angle_Xaxis(s1)*180/PI << endl;
	cout << "Angolo s2 " << angle_Xaxis(s2)*180/PI << endl;
	cout << "Angolo s3 " << angle_Xaxis(s3)*180/PI << endl;
	cout << endl;

	cout << "CGAL Square circulator" << endl;
	Point a(4,4), b(4,8), c(8,8), d(8,4);
	Polygon_2 poly1, poly2;
	poly1.push_back(a);
	poly1.push_back(b);
	poly1.push_back(c);
	poly1.push_back(d);

	poly2.push_back(a);
	poly2.push_back(c);
	poly2.push_back(b);
	poly2.push_back(d);

	cout << "Correct Square" << endl;
	Ep_circulator i=poly1.edges_circulator();
	Segment ini=*i;
	do{
		cout << "Segmento " << *i << endl;
		cout << "Next segment angle " << angle_Xaxis(*i)*180/PI << endl;
		++i;
	}while(*i != ini);
	Vp_circulator j=poly1.vertices_circulator();
	Point v_ini=*j;
	do{
		cout << "Vertice " << *j << endl;
		cout << "Next segment angle " << angle_Xaxis(*j,*(j+1))*180/PI << endl;
		++j;
	}while(*j != v_ini);
	cout << endl;

	cout << "Incorrect Square - Clepsydra" << endl;
	i=poly2.edges_circulator();
	ini=*i;
	do{
		cout << "Segmento " << *i << endl;
		cout << "Next segment angle " << angle_Xaxis(*i)*180/PI << endl;
		++i;
	}while(*i != ini);
	j=poly2.vertices_circulator();
	v_ini=*j;
	do{
		cout << "Vertice " << *j << endl;
		cout << "Next segment angle " << angle_Xaxis(*j,*(j+1))*180/PI << endl;
		++j;
	}while(*j != v_ini);
	cout << endl;

	cout << "Checking export functions FRACT=" << FRACT << endl;
	SAFEARRAY * sa=poly2safe(poly1);
	SAFEARRAY * lsa=simplify(&sa,FRACT,MIN_DIST,false);
	Polygon_2 poly3=safe2poly(&lsa);
	j=poly3.vertices_circulator();
	v_ini=*j;
	do{
		cout << "Vertice " << *j << endl;
		cout << "Next segment angle " << angle_Xaxis(*j,*(j+1))*180/PI << endl;
		++j;
	}while(*j != v_ini);
	cout << endl;

	Bbox_2 box(
			 poly2.bbox().xmin(),
			 poly2.bbox().ymin(),
			 poly2.bbox().xmax(),
			 poly2.bbox().ymax()
			 );
	
	Polygon_2 contour;
	contour.push_back(Point(box.xmin(),box.ymin()));
	contour.push_back(Point(box.xmax(),box.ymin()));
	contour.push_back(Point(box.xmax(),box.ymax()));
	contour.push_back(Point(box.xmin(),box.ymax()));
	j=contour.vertices_circulator();
	v_ini=*j;
	do{
		cout << "Bbox Point: " << *j << endl;
		++j;
	}while(*j != v_ini);

	return 0;
}

